https://leetcode.cn/problems/implement-queue-using-stacks/


typedef int STDatatype;
typedef struct Stack
{
    STDatatype* a;
    int top;
    int capacity;
}Stack;

void StackInit(Stack* ps)
{
    assert(ps);
    ps->a = NULL;
    ps->top = ps->capacity = 0;
}
void StackPush(Stack* ps, STDatatype x)
{
    assert(ps);
    if (ps->top == ps->capacity)
    {
        ps->capacity = ps->capacity == 0 ? 4 : 2 * ps->capacity;
        STDatatype* tmp = (STDatatype*)realloc(ps->a, ps->capacity * sizeof(STDatatype));
        assert(tmp);
        ps->a = tmp;

    }
    ps->a[ps->top] = x;
    ps->top++;


}
void StackPop(Stack* ps)
{
    assert(ps);
    assert(ps->top);
    ps->top--;

}
STDatatype StackTop(Stack* ps)
{
    assert(ps);
    assert(ps->top);
    return ps->a[ps->top - 1];
}
int StackSize(Stack* ps)
{
    assert(ps);
    return ps->top;
}
void StackDestroy(Stack* ps)
{
    assert(ps);
    free(ps->a);
    ps->top = ps->capacity = 0;
}


bool StackEmpty(Stack* ps)
{
    assert(ps);
    if (ps->top == 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}


typedef struct {
    Stack stpush;
    Stack stpop;
} MyQueue;

int myQueuePeek(MyQueue* obj) {
    assert(obj);
    if (StackEmpty(&obj->stpop))
    {
        while (StackSize(&obj->stpush))
        {
            int back = StackTop(&obj->stpush);
            StackPush(&obj->stpop, back);
            StackPop(&obj->stpush);
        }
    }
    return StackTop(&obj->stpop);
}

bool myQueueEmpty(MyQueue* obj) {
    return StackEmpty(&obj->stpop) && StackEmpty(&obj->stpush);
}

void myQueueFree(MyQueue* obj) {
    StackDestroy(&obj->stpop);
    StackDestroy(&obj->stpush);
    free(obj);
}
MyQueue* myQueueCreate() {
    MyQueue* pq = (MyQueue*)malloc(sizeof(MyQueue));
    StackInit(&pq->stpush);
    StackInit(&pq->stpop);
    return pq;
}

void myQueuePush(MyQueue* obj, int x) {
    assert(obj);
    StackPush(&obj->stpush, x);
}

int myQueuePop(MyQueue* obj) {
    assert(obj);
    int ret = myQueuePeek(obj);
    StackPop(&obj->stpop);
    return ret;
}